<template>
  <div>
    <!-- 搜索 -->
    <!-- 索赔申请 -->
    <TopFilter ref="TopFilterss" :list="topFilterInit" :cols="3" :collapse="collapse" labelWidth="120" @filterChange="changeHandle"></TopFilter>
    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :params="fetchParams"
      :dataSource="dataList"
      :fetchapi="fetchApi"
      :datakey="'records'"
      :onColumnsChange="(columns) => (this.columns = columns)"
      :onRowSelectChange="selectChange"
    >
      <template slot="controls" slot-scope="props">
        <!--        <multiuse-button size="small" type="primary" icon="el-icon-plus" @click="exportFileBtn()">导出</multiuse-button>-->
      </template>
    </FilterTable>

    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right',
      }"
    >
      <multiuse-button type="primary" :click="saveDialog.bind()">添 加</multiuse-button>
      <multiuse-button @click="closeDialog">关 闭</multiuse-button>
    </div>
  </div>
</template>
<script>
// import { getSpList}  from '@/api/claim/factory/ClaimQueryFactory/index';
import { getSpList } from '@/api/claim/dealer/ClaimQueryDealer/index';
import { getPartType } from '@/api/claim/dealer/ClaimStatementMaintain/index';

export default {
  props: ['rowData'],
  //  mixins: [dictionary],
  components: {},
  data() {
    return {
      dataList: [],
      visible: false,
      visibleDrawer: false,
      collapse: false,
      infoId: null,
      topFilterInit: this.topFilterInitFun(),
      flterValue: {}, //参数
      fetchApi: getSpList,
      columns: this.creatHeader(),
      fetchParams: { ifComm: this.rowData.carType,claimStatus : 55131003 ,status:3}, //ipa 接口
      selectedRows: [], //选中经销商
      dialogTitle: '选择车辆',
      visibleAdd: false,
      visibleEdit: false,
      // rowData:{}
    };
  },
  created() {
    this.chuqi();
  },
  methods: {
    //选中
    selectChange(rows) {
      this.selectedRows = rows;
      console.log(this.selectedRows);
    },
    //保存
    saveDialog() {
      this.$emit('save', this.selectedRows);
    },
    //取消操作
    closeDialog() {
      this.$emit('close', { visible: false, data: this.selectedRows, type: 'close' });
    },
    //搜索数据
    topFilterInitFun() {
      return [
        { type: 'INPUT', label: '索赔单号', fieldName: 'claimNo', placeholder: '请输入', initialValue: '' },
        { type: 'SELECT', label: '索赔类型', fieldName: 'cmsClaimType', placeholder: '请选择', initialValue: '', itemList: [] },
        { type: 'INPUT', label: 'VIN', fieldName: 'vin', placeholder: '请输入', initialValue: '' },
        { type: 'RANGE_DATE', label: '审核时间', fieldName: 'startTime|endTime', placeholder: '请输入', initialValue: '' },
      ];
    },
    //搜索获取数据
    changeHandle(val) {
      this.fetchParams = Object.assign({ ifComm: this.rowData.carType,claimStatus : 55131003,status:3 }, val);
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: (props) => {
            return <span>{props.row.index + 1}</span>;
          },
        },
        // { title: '索赔单状态', dataIndex: 'statusStr', sorter: true },
        { title: '索赔单号', dataIndex: 'claimNo', sorter: true },
        { title: '索赔类型', dataIndex: 'cmsClaimTypeStr', sorter: true },
        { title: '车辆属性', dataIndex: 'ifCommStr', sorter: true },
        { title: '维修工单号', dataIndex: 'roNo', sorter: true },
        { title: 'VIN', dataIndex: 'vin', sorter: true },
        // { title: '车牌号', dataIndex: 'licenseNo', sorter: true },
        // { title: '车型名称', dataIndex: 'modelName', sorter: true },
        // { title: '主损件代码', dataIndex: 'partCode', sorter: true },
        // { title: '主损件名称', dataIndex: 'partName', sorter: true },
        //{ title: '供应商', dataIndex: 'supName', sorter: true },
        // { title: '行驶里程', dataIndex: 'driveMile', sorter: true },
        // { title: '故障现象代码', dataIndex: 'faultCode', sorter: true },
        // { title: '故障现象名称', dataIndex: 'faultName', sorter: true },
        // { title: '故障原因代码', dataIndex: 'frCode', sorter: true },
        // { title: '故障原因名称', dataIndex: 'frName', sorter: true },
        // { title: '驳回次数', dataIndex: 'partCode', sorter: true },
        { title: '索赔金额', dataIndex: 'finalSumAmount', sorter: true },
        { title: '工时费', dataIndex: 'labourFinalPrice', sorter: true },
        { title: '配件费', dataIndex: 'partrFinalPrice', sorter: true },
        { title: '附加费用', dataIndex: 'addFinalPrice', sorter: true },
        // { title: '保修起始日期', dataIndex: 'serviceBeginDate', sorter: true },
        // { title: '保修截止日期', dataIndex: 'serviceEndDate', sorter: true },
        // { title: '生产日期', dataIndex: 'prodDate', sorter: true },
        // { title: '销售日期', dataIndex: 'saleDate', sorter: true },
        // { title: '维修日期', dataIndex: 'repairBeginDate', sorter: true },
        // { title: '申请时间', dataIndex: 'applyAt', sorter: true },
        // { title: '申请人', dataIndex: 'ceratedBy', sorter: true },
        { title: '审核时间', dataIndex: 'checkAt', sorter: true },
        { title: '审核人', dataIndex: 'checkBy', sorter: true },
      ];
    },
    async chuqi() {
      const res2 = await getPartType({ type: 5501 });
      if (res2.resultCode == 200) {
        this.topFilterInit.find((x) => x.fieldName == 'cmsClaimType').initialValue = '';
        this.topFilterInit.find((x) => x.fieldName == 'cmsClaimType').itemList = res2.data.map((y) => ({ text: y.codeCnDesc, value: y.codeId }));
      }
    },
    close() {
      this.visible = false;
    },
    chooseOrderNo() {
      this.visible = true;
    },
    chooseDealerNo() {
      this.visibleAdd = true;
    },
    saveAdd(val) {
      this.topFilterInit.find((x) => x.fieldName == 'ownerCode').initialValue = val[0].dealerCode;
      this.dealer = { ...val[0] };
      this.visibleAdd = false;
    },
    closeAdd() {
      this.visibleAdd = false;
    },
    save(obj) {
      this.topFilterInit.find((x) => x.fieldName == 'modelCode').initialValue = obj[0].modelCode;
      this.visible = false;
    },
    add() {
      this.visibleAdd = true;
    },
    editclose() {
      this.visibleEdit = false;
      this.fetchParams = { ...this.fetchParams };
    },
    edit(val) {
      this.rowData = val;
      this.visibleEdit = true;
    },
    editsave() {
      this.visibleEdit = false;
      this.fetchParams = { ...this.fetchParams };
    },
  },
};
</script>

<style lang="less" scoped></style>
